import baseUrl from "./baseUrl.js";
import request from "@/utils/http.request.js";

const dict = {
    /**
     * 获取数据字典树
     * @param keyword 关键字
     * @param _response
     * @param _finally
     * @return {*|void}
     */
    getTree(keyword, _response, _finally = null) {
        return request.get(`${baseUrl.dict}/tree`, { keyword: keyword }, _response, _finally);
    },
    /**
     * 添加一级数据字典
     * @param jsonObj 请求对象
     * @param _response 
     * @param _finally 
     * @returns 
     */
    addFirst(jsonObj, _response, _finally = null) {
        return request.postWithJson(`${baseUrl.dict}`, jsonObj, _response, _finally)
    },
    /**
     * 添加二级数据字典
     * @param jsonObj 请求对象
     * @param _response 
     * @param _finally 
     * @returns 
     */
    addChild(jsonObj, _response, _finally = null) {
        return request.postWithJson(`${baseUrl.dict}/child`, jsonObj, _response, _finally)
    },
    /**
     * 修改字典
     * @param jsonObj 字典对象
     * @param _response 
     * @param _finally 
     * @returns 
     */
    edit(jsonObj, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.dict}`, jsonObj, _response, _finally)
    },
    /**
   * 删除字典
   * @param dictId 字典id
   * @param _response 
   * @param _finally 
   * @returns 
   */
    delete(dictId, _response, _finally = null) {
        return request.deleteWithouParam(`${baseUrl.dict}/${dictId}`, _response, _finally)
    },
    /**
     * 根据一级字典代码获取二级字典列表
     * @param code 数据字典代码
     * @param _response 
     * @param _finally 
     * @returns 
     */
    getListByCode(code, _response, _finally = null) {
        return request.get(`${baseUrl.dict}/getByCode`, { code: code }, _response, _finally);
    }
};

export default dict;